import logging
import os

from facade.loggerfacade import get_filelogger

nCount = 0
TopPath = os.path.abspath(os.path.dirname(os.path.dirname(os.getcwd())))
AMSPath = os.path.join(TopPath, "download", "cdxg_ams")
FILE_DOWNLOAD_PATH = os.path.join(AMSPath, 'download')
DIR_TIME_DETAILS = os.path.join(FILE_DOWNLOAD_PATH, 'cover')
# 转换成base32编码
logger=None

def main(logger1: logging.Logger):
    global logger
    logger = logger1
    nCount = 0
    provider = 'ametsocjournal'
    filePath = provider + '_cover.txt'
    sPath = DIR_TIME_DETAILS
    print('path:' + sPath)

    with open(filePath, mode='w', encoding='utf-8') as f:
        for path, dirNames, fileNames in os.walk(sPath):
            for fileName in fileNames:
                #分离文件名与扩展名 返回文件名和扩展名
                journal = os.path.splitext(fileName)[0]
                line = provider + '@' + journal + '★/smartlib/' + provider + '/' + fileName + '\n'
                f.write(line)
                nCount += 1
    print('nCount:' + str(nCount))


if __name__ == "__main__":
    logger1 = get_filelogger("./logs")
    main(logger1)